package my.jwds.p1436;

import java.util.*;

public class DestCity {
    public static void main(String[] args) {
        DestCity obj = new DestCity();
        String [][] arr = {{"London","New York"},{"New York","Lima"},{"Lima","Sao Paulo"}};
        List<List<String>> list = new ArrayList<>();
        for (int i = 0; i < arr.length; i++) {
            list.add(Arrays.asList(arr[i]));
        }
        System.out.println(obj.destCity(list));
    }

    public String destCity(List<List<String>> paths) {
        Set<String> map = new HashSet<>();
        int length = paths.size();
        for (int i = 0; i < length; i++) {
            map.add(paths.get(i).get(0));
        }
        for (int i = 0; i < length; i++) {
            String targetCity = paths.get(i).get(1);
            if (!map.contains(targetCity)){
               return targetCity;
            }
        }

        return null;
    }
}
